
<script setup>
import { getProductDetailService } from '@/api/product';
import { ref , onMounted,toRefs} from 'vue'
import {CircleCloseFilled} from '@element-plus/icons-vue'
// 接收v-model传递的值
const props = defineProps(['modelValue', 'productId'])
const { modelValue, productId } = toRefs(props)
// 发射事件
const emit = defineEmits(['update:modelValue'])
// 关闭组件
const notShow = () => {
  emit('update:modelValue', false)
}
const productDetail = ref({})
const images = ref([])
const getProductDetail = async () => {
  const res = await getProductDetailService(productId.value)
  productDetail.value = res.data.data
  console.log(productDetail.value)
  // 将 images 字段从字符串转换为数组
  images.value = JSON.parse(productDetail.value.images || '[]')
}
onMounted(() => {
  getProductDetail()
})
</script>
 
<template> 
  <div class="mask animate__animated animate__fadeIn" v-if="modelValue">
    <div class="container animate__animated animate__zoomIn">
      
      <div class="left">
        <!-- 轮播图 -->
        <el-carousel height="600px">
          <el-carousel-item v-for="item in images" :key="item">
            <img :src="item" alt="" class="carousel-image">
          </el-carousel-item>
        </el-carousel>
      </div>
      <div class="right">
        <div class="close-btn">
          <el-icon color="#fe455d" size="25px" @click="notShow">
            <CircleCloseFilled />
          </el-icon>
        </div>
        <div class="header">
          <div class="avatar">
            <img class="avatar-img"
              :src="'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png'"
              style="width: 60px; border-radius: 50%; outline: none;">
            <span style="margin-left: 15px; color: #5c5c5c; font-size: 18px; ">骑老爷爷过马路</span>
          </div>
        </div>
        <div class="content">
          <div class="note-content">
            <div class="title">
              <h3>{{ productDetail.title }}</h3>
            </div>
            <div class="description">
              <p>{{ productDetail.description }}</p>
            </div>
          </div>
          <div class="comments-content">
            
          </div>
          
        </div>
        <div class="footer">
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
.animate__animated {
  animation-fill-mode: both;
  animation-duration: .5s;
}
.mask {
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.4);
  display: flex;
  justify-content: center;
  align-items: center;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
  .container{
    width: 900px;
    height: 600px;
    background-color: rgb(250, 250, 250);
    border-radius: 15px;
    display: flex;

    
    .left{
      width: 500px;
      height: auto;
      .carousel-image {
        width: 100%;
        height: 100%;
        object-fit: contain; /* 保持图片完整，并适应容器 */
        object-position: center; /* 图片居中显示 */
      }
      
    }


    .right{
      display: flex;
      position: relative;
      flex-direction: column;
      width: 400px;
      height: 100%;
      .header, .footer{
        text-align: center;
        position: absolute;
        height: 60px;
        width: 400px;
        z-index: 10;
      }
      .close-btn {
        position: absolute;
        right: 20px;
        top: 20px;
        cursor: pointer;
        z-index: 11;
        transition: all .2s;
        &:hover {
          transform: scale(1.3);
        }
      }
      .header{
        top: 0;
        .avatar {
          display: flex;
          align-items: center;
        }
      }
      .content{
        padding: 80px 15px 80px; /* 留出顶部和底部的空间 */
        overflow-y: auto;
        height: 100% ; /* 减去header和footer的高度 */
        box-sizing: border-box;
        .title{
        margin-top: 15px;
        }
        .description{
          padding: 15px 0 15px 0;
          border-bottom: 1px solid #d3d1d1;
          p{
            font-size: 16px;
            color: #5c5c5c;
            line-height: 1.5;
          }
        }
      }
      .footer{
        bottom: 0;
      }
    }
  }

}
</style>